using KPIS.GERP.Models.HRM;

namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update113 : DbMigration
    {
        public override void Up()
        {
            var db = new GERPContext(true);
            db.Database.ExecuteSqlCommand(@"
IF NOT EXISTS (SELECT * FROM hrm_ps_absence_types WHERE absence_type_seq = 10)
BEGIN
    SET IDENTITY_INSERT dbo.hrm_ps_absence_types ON;
    insert into hrm_ps_absence_types (absence_type_seq, absence_type_name ) values (10, 'mock');
    SET IDENTITY_INSERT dbo.hrm_ps_absence_types OFF;
END

");

            RenameTable(name: "dbo.rule_absence", newName: "hrm_ps_absence_rules");
            AddForeignKey("dbo.hrm_ps_absence_rules", "emp_type_seq", "dbo.hrm_ps_employee_types", "emp_type_seq", cascadeDelete: true);
            AddForeignKey("dbo.hrm_ps_absence_rules", "absence_type_seq", "dbo.hrm_ps_absence_types", "absence_type_seq", cascadeDelete: true);
            CreateIndex("dbo.hrm_ps_absence_rules", "emp_type_seq");
            CreateIndex("dbo.hrm_ps_absence_rules", "absence_type_seq");
        }
        
        public override void Down()
        {
            DropIndex("dbo.hrm_ps_absence_rules", new[] { "absence_type_seq" });
            DropIndex("dbo.hrm_ps_absence_rules", new[] { "emp_type_seq" });
            DropForeignKey("dbo.hrm_ps_absence_rules", "absence_type_seq", "dbo.hrm_ps_absence_types");
            DropForeignKey("dbo.hrm_ps_absence_rules", "emp_type_seq", "dbo.hrm_ps_employee_types");
            RenameTable(name: "dbo.hrm_ps_absence_rules", newName: "rule_absence");
        }
    }
}
